package com.niiwoo.civet.account.service.dubbo.withholdProtocol;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.account.dao.entity.WithholdProtocolConfirmOrder;
import com.niiwoo.civet.account.dto.response.ApplyWithholdProtocolResponseDTO;
import com.niiwoo.civet.account.dto.response.ConfirmWithholdProtocolResponseDTO;
import com.niiwoo.civet.account.dto.response.WithholdProtocolResultDTO;
import com.niiwoo.civet.account.service.local.withholdProtocol.WithholdProtocolService;
import com.niiwoo.civet.account.service.withholdProtocol.WithholdProtocolDubboService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@Service(version = "1.0.0")
public class WithholdProtocolDubboServiceImpl implements WithholdProtocolDubboService {

    @Autowired
    private WithholdProtocolService withholdProtocolService;
    @Autowired
    private RedissonClient redissonClient;

    @Override
    public ApplyWithholdProtocolResponseDTO applyWithholdProtocol(String userId, String orgId) {
        return withholdProtocolService.applyWithholdProtocol(userId,orgId);
    }

    @Override
    public ConfirmWithholdProtocolResponseDTO confirmWithholdProtocol(Long orderId, String securityCode) {
        return withholdProtocolService.confirmWithholdProtocol(orderId,securityCode);
    }

    @Override
    public WithholdProtocolResultDTO getWithholdProtocolResultForLocal(String userId, String orgId) {
        return withholdProtocolService.getWithholdProtocolResultForLocal(userId,orgId);
    }

    @Override
    public WithholdProtocolResultDTO getWithholdProtocolResultForRemote(String userId, String orgId) {
        return withholdProtocolService.getWithholdProtocolResultForRemote(userId,orgId);
    }

    /**
     每两分钟执行一次
     检索当前10分钟的数据
     如果成功，修改状态；
     如果失败，当前数据不做处理；
     一条数据，最小补单一次，最多补单五次；
     宝付验证码有效时间5分钟
     快钱验证码有效时间15分钟
     */
    @Override
    public void autoCompensation() {
         try{
             withholdProtocolService.autoCompensation();
         }catch (Exception e){
             log.error("auto-compensation RunTimeException:",e);
         }
    }

    public void checkUserWithholdProtocolSigned(){
        withholdProtocolService.checkUserWithholdProtocolSigned();
    }
}
